<template>
  <view>
    <base-paging ref="paging" :add-fad="false" :datasource="datasource" :tabs="tabs">
      <template #default="{ list }">
        <template v-for="(item, index) in list" :key="index">
          <base-card>
            <view @click.stop="toBasePath('/detail?id=' + item.id)">
              <view>
                <text style="font-weight: bold; font-size: 1.2em; color: #000">{{ item.course }}</text>
              </view>
              <view>
                <text>{{ item.createTime }}</text>
              </view>
            </view>
          </base-card>
        </template>
      </template>
    </base-paging>
  </view>
</template>

<script>
import {Msg, toPath} from "@/utils/BaseUtils";
import {LearnApi as Api} from "@/comms/api/learnApi";

export default {
  data() {
    return {
      toPath,
      // 未学习:unlearned 已学习:learned
      tabs: [
        {key: 'unlearned', name: '未学习',},
        {key: 'learned', name: '已学习'},
      ]
    }
  },
  mounted() {
  },
  onShow() {
    this.reload()
  },
  methods: {
    reload() {
      this.$refs.paging.reload();
    },
    datasource({pageNo, tab}) {
      return Api.page({pageNo, flag: tab.key})
    },
    remove({id}) {
      Msg.confirm("确定删除该调休信息?")
          .then(() => {
            Api.delete({id}).then(res => {
              this.reload();
              Msg.success("删除成功")
            })
          })
    },
    toBasePath(path) {
      toPath("/pages/mys/learn" + path)
    }
  }
}
</script>

<style lang="scss" scoped>
.uni-card {
  margin-bottom: 15rpx;
}

.button-group {
  button {
    margin-left: 10rpx;
  }
}
</style>
